package com.pylc.model.entity;

import org.hibernate.annotations.Cascade;

import javax.persistence.*;
import java.util.Set;

/**
 * @author Lindsey
 */
@Entity
@Table
public class GoodsCategory extends BaseEntity {
    private String name;
    private Integer sortOrder;
    private GoodsCategory parent;
    private Integer depth;
    private Set<GoodsCategory> children;
    private Boolean isShowed;
    private Boolean isShowInIndex;

    @Column
    public Boolean getShowed() {
        return isShowed;
    }

    public void setShowed(Boolean showed) {
        isShowed = showed;
    }

    @Column
    public Boolean getShowInIndex() {
        return isShowInIndex;
    }

    public void setShowInIndex(Boolean showInIndex) {
        isShowInIndex = showInIndex;
    }

    @OneToMany(fetch = FetchType.LAZY)
    @JoinColumn(name = "parent_id")
    @Cascade(value = {org.hibernate.annotations.CascadeType.DELETE})
    @OrderBy("sortOrder asc")
    public Set<GoodsCategory> getChildren() {
        return children;
    }

    public void setChildren(Set<GoodsCategory> children) {
        this.children = children;
    }

    @Column
    public Integer getDepth() {
        return depth;
    }

    public void setDepth(Integer depth) {
        this.depth = depth;
    }

    @Column
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "parent_id")
    public GoodsCategory getParent() {
        return parent;
    }

    public void setParent(GoodsCategory parent) {
        this.parent = parent;
    }

    @Column
    public Integer getSortOrder() {
        return sortOrder;
    }

    public void setSortOrder(Integer sortOrder) {
        this.sortOrder = sortOrder;
    }


}
